import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        loading: false,
        login: false,
        deleteMask: false,
        deleteId: 0,
        indexdata: [],
        userlist: '',
        username: '',
        userid: 0,
        avatar: '',
        titlimg: null,
        tourl: '',
        del: 0,
        resultList: {},
        ShutFullscreen: false

    },
    mutations: {
        homelist(state, nowdata) {
            // let datalist = {};
            // for (let i in nowdata) {
            //     if (nowdata.hasOwnProperty(i)) { // hasOwnProperty()  过滤原型链
            //         datalist[nowdata[i].uid] = {
            //             'imgurl': nowdata[i].imgurl,
            //             'username': nowdata[i].username,
            //             'uid': nowdata[i].uid,
            //             'datetime': nowdata[i].datetime,
            //             'backpostion': nowdata[i].backpostion,
            //         }
            //     }

            // }
            state.indexdata = nowdata;
        },
        loginMask(state, data) {
            state.login = data
        },
        userinfo(state, data) {
            state.userid = data.qq
            state.username = data.name
            state.avatar = data.avatar
        },
        uodataUserlist(state, data) {
            state.userlist = data
        },
        deleteIndex(state) {
            state.userlist.splice(state.deleteId, 1)

        },
        deleteMaskState(state, data) {
            state.deleteMask = data.off
            state.deleteId = data.mark
            state.del = data.del
        },
        updataTourl(state, data) {
            state.tourl = data

        },
        updataResult(state, data) {
            state.resultList = data

        },
        changeShutFullscreen(state, data) {
            state.ShutFullscreen = data
        }

    },
    actions: {
        delete({ commit }) {
            commit('deleteIndex')
        }
    },
    getters: {
        updatelist: state => {
            let list = [];
            if (state.indexdata.state == "update") {
                list = [];
            } else {
                list = state.indexdata
            }
            return list
        }
    }
})